Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate Clusters resourceCount from BundleDeployments instead of GitRepos #3102

Merged
merged 7 commits into from
Dec 12, 2024

Conversation

aruiz14
Copy link
Contributor

@aruiz14 aruiz14 commented Nov 27, 2024

Refers to rancher/rancher#46916

Description

status.resourceCounts for cluster.fleet.cattle.io is calculated from GitRepos statuses, which include an equivalent resourceCounts field. This causes the count to be incorrect, since a GitRepo could deploy resources to different Clusters.

How to reproduce the issue

  1. Setup Rancher/Fleet with more than 1 downstream clusters
  2. Add a GitRepo that deploys to all downstream clusters
  3. Describe the status of any of the clusters and observe that status.resourceCounts is wrong, since it also includes resources deployed to other namespaces.

Description of the fix

This can be fixed by populating Clusters' status.resourceCounts from their respective BundleDeployments, similarly to how it's calculated for GitRepos. In order to do this in a clean way, I had to move that code out of the gitops reconciler to its own package.

In addition, I've added some changes to make the existing code a bit more efficient:

  • Filter bundleDeployment.Items while it's being modified, removing the need to keep a separate map of deleted objects.
  • Create an index (map) of bundles to be deleted, instead of having a double for loop.
  • Removed duplicity of repoKey type, which was the same as types.NamespacedKey.

@aruiz14 aruiz14 requested a review from a team as a code owner November 27, 2024 11:03
@aruiz14 aruiz14 changed the title Calculate resourceCount from BundleDeployments instead of GitRepos Calculate Clusters resourceCount from BundleDeployments instead of GitRepos Nov 27, 2024
@aruiz14 aruiz14 force-pushed the cluster-resources-from-bd branch from b7f3e65 to c00959f Compare November 27, 2024 11:09
Copy link
Contributor

@weyfonk weyfonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!
Approval pending discussion on whether or not to include Fleet agent bundles in cluster resource counts.

internal/cmd/controller/reconciler/cluster_controller.go Outdated Show resolved Hide resolved
internal/cmd/controller/reconciler/cluster_controller.go Outdated Show resolved Hide resolved
@aruiz14 aruiz14 force-pushed the cluster-resources-from-bd branch from 602143e to f295c3f Compare December 4, 2024 11:01
@aruiz14 aruiz14 requested review from weyfonk and manno December 4, 2024 11:02
Copy link
Contributor

@weyfonk weyfonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this! :)

@manno manno modified the milestones: v2.10.1, v2.11.0 Dec 4, 2024
@aruiz14 aruiz14 enabled auto-merge (squash) December 12, 2024 11:55
@aruiz14 aruiz14 merged commit c22332c into rancher:main Dec 12, 2024
12 checks passed
@aruiz14 aruiz14 deleted the cluster-resources-from-bd branch December 12, 2024 12:29
aruiz14 added a commit to aruiz14/fleet that referenced this pull request Dec 12, 2024
aruiz14 added a commit to aruiz14/fleet that referenced this pull request Dec 12, 2024
aruiz14 added a commit to aruiz14/fleet that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants